<template>
	<view class="mainpadding beijingse">
		<view class="mainpadding radius ffffff sahngbj dingwei" v-for="item in list" :key="item.id" @click="selectfn(item)">
			<view class="hubtn flexcenter" v-if="item.tt_type==1">个人</view>
			<view class="hubtn flexcenter" v-else>单位</view>
			<view class="xiahuaxian">
				<view class="titletext fonweight zhonghei ">{{item.name}}</view>
			</view>
			<view class="flexbetween margin_top">
				<view class="flexleft" v-if="item.status==0" @click.stop="editmr(item.id)">
					<view class="weixz margin_right1" style="width: 32rpx;height: 32rpx;"></view>
					<view class="strongtext xiaohei" >设为默认</view>
				</view>
				<view class="flexleft" v-else>
					<view class="margin_right1">
						<u-icon name="checkmark-circle-fill" color="#FF8000" size="20"></u-icon>
					</view>
					<view class="strongtext xiaohei" >默认</view>
				</view>
				<view class="flexright">
					<view class="flexleft margin_right3" @click.stop="edititem(item.id)">
						<view class="margin_right1">
							<u-icon name="file-text" color="#666666" size="19"></u-icon>
						</view>
						<view class="strongtext xiaohei">编辑</view>
					</view>
					<view class="flexleft" @click.stop="delitem(item.id)">
						<view class="margin_right1">
							<u-icon name="trash" color="#666666" size="19"></u-icon>
						</view>
						<view class="strongtext xiaohei">删除</view>
					</view>
				</view>
			</view>
		</view>
		<!--  -->
		<view class="gudingdb  mainpadding">
			<view class="bigbtn" @click="tzxzshdz">+新增发票抬头</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				list:[],
				tt_type:0,
			}
		},
		onLoad(options) {
			if(options.tt_type){
				this.tt_type = options.tt_type
			}
		},
		onShow() {
			this.init()
		},
		methods: {
			selectfn(item){
				if(this.tt_type){
					uni.$emit("selecttt",item)
					uni.navigateBack(1)
				}
			},
			init(isPage, page) {
				let _this = this;
				let data = {
					tt_type:this.tt_type
				}
				let url = '/api/user/userTtIndex'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						this.list = res.data
					}
				})
			},
			editmr(id){
				httpRequest.request("/api/user/editUserTt", 'GET', {
					status: 1,
					id
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if(res.code==1){
						this.init()
					}
				})
			},
			delitem(id){
				httpRequest.modal('提示', '是否确认删除', true, (resp) => {
					if (resp) {
						httpRequest.request('/api/user/delUserTt', 'GET', {
							id: id,
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			// 跳转新增发票抬头
			tzxzshdz() {
				uni.navigateTo({
					url: '/pages_wode/tianxiefp'
				})
			},
			edititem(id){
				uni.navigateTo({
					url: '/pages_wode/tianxiefp?id='+id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.hubtn {
		position: absolute;
		top: 0;
		right: 0;
		font-size: 22rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		width: 115rpx;
		height: 44rpx;
		background: #fff5ec;
		border-radius: 0rpx 14rpx 0rpx 14rpx;
		color: #FF9341;
	}

	.sahngbj {
		margin-top: 30rpx;
	}

	.sahngbj:first-child {
		margin-top: 0rpx;
	}
</style>